package com.repast.controller;

import com.repast.common.ServerResponse;
import com.repast.pojo.Appoint;
import com.repast.service.IAppointService;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by EastCool·Lee on 2017/6/21.
 */
@Controller
@RequestMapping("/appoint/")
public class AppointController {
	
	@Autowired
	private IAppointService appointService;
	
	//生成预约表
    @RequestMapping("makeAppoint.do")
    @ResponseBody
    public ServerResponse makeAppoint(String json) throws Exception{
    	JSONObject jsonStr = JSONObject.fromObject(json);
    	Appoint appoint = new Appoint();
    	String appointName = jsonStr.getString("appointName");
    	appoint.setAppointName(appointName);
    	appoint.setAppointPhone(jsonStr.getString("appointPhone"));
    	appoint.setAppointCreateTime(jsonStr.getString("appointCreateTime"));//选择的时间段
    	appoint.setOpenid(jsonStr.getString("openid"));
    	appoint.setDeskId(jsonStr.getInt("deskId"));
        return appointService.makeAppoint(appoint);
    }
    
    //取消预约,0取消预约成功,1017系统异常,取消预约失败,1018未查询到你的预约
    @RequestMapping("abolish.do")
    @ResponseBody
    public ServerResponse abolishAppoint(Integer appointId){
    	return appointService.abolishAppoint(appointId);
    }
    
    @RequestMapping("judgeAppoint.do")
    @ResponseBody
    //我要预约调一次接口,查询大于当前时间是否已经有预约
    public ServerResponse judgeAppoint(String  openid) throws Exception{
    	return appointService.judgeAppoint(openid);
    }
    
    
}
